package pl.enigmatic.random;

import pl.enigmatic.math.MathUtil;


public abstract class Random<X> {

	public static double getDouble() {
		return Math.random();
	}

	public static double getDouble(final double min, final double max) {
		final double alpha = getDouble();
		return (1 - alpha) * min + alpha * max;
	}

	public static int getInteger(final int min, final int max) {
		return MathUtil.wrap(min, max, (int) Math.round(getDouble(min, max)));
	}

	public static int getInteger() {
		return getInteger(Integer.MIN_VALUE, Integer.MAX_VALUE);
	}

	private boolean fixed = false;
	private X fixedValue = null;

	public abstract X getRandomValue();

	public X get() {
		if (fixed) {
			return fixedValue;
		} else {
			return getRandomValue();
		}
	}

	public X draw() {
		return get();
	}

	public X rand() {
		return get();
	}

	public void setFixed(final X fixed) {
		this.fixed = true;
		fixedValue = fixed;
	}

	public void setRandom() {
		this.fixed = false;
		fixedValue = null;
	}

	public boolean isFixed() {
		return fixed;
	}

	public X getFixedValue() {
		return fixedValue;
	}
}
